package com.shengyo.model.dao.impl;

import java.sql.SQLException;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

import com.shengyo.model.bean.Camera;
import com.shengyo.model.dao.ICameraDAO;


public class CameraDAOImpl extends BaseDAOImpl implements ICameraDAO{

	@Override
	public void delete(Camera camera) {
		this.getHibernateTemplate().delete(camera);	
	}

	@Override
	public Camera findByCameraUrl(String url) {
		List<?> list = this.getHibernateTemplate().find("from camera b where b.url=?",new Object[]{url});
		if (list != null && !list.isEmpty())
			return (Camera) list.get(0);
		else
			return null;
	}

	@Override
	public Camera findById(String id) {
		return (Camera) this.getHibernateTemplate().load(Camera.class, id);
	}

	@Override
	public List<?> findAll() {
		return this.getHibernateTemplate().find("from camera");
	}


	@Override
	public Object findById(int id) {
		return null;
	}

	@Override
	public List<Camera> findAllPiexl(int first, int max) {
		return null;
	}

	@Override
	public List<?> findAll(final int first, final int max) {
        return this.getHibernateTemplate().executeFind(new HibernateCallback(){

			public Object doInHibernate(Session session)
					throws HibernateException, SQLException {
				return session.createQuery("from camera").setFirstResult(first).setMaxResults(max).list();
			}
			
		});
	}


}
